package org.aileen.blog.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    //指定未登录拦截的路径,除了登录接口,其他接口都需要登录,所以我们这里需要重写addInterceptors方法
    @Autowired
    private LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加登录拦截器
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/blog/**","/user/**") //拦截所有以/blog/和/user/开头的请求
                .excludePathPatterns("/user/login"); //排除登录接口

    }
}
